#ifndef _PARSER_
#define _PARSER_

#define BUFFER_BLOCK_SIZE 100
#define SYMTABLE_ARRAY_SIZE 20000

#include <TokenTyp.h>
#include <Symtable.h>
#include <TokenHierarchy.h>
#include <ScannerFSM.h>
#include <ScannerFSMExceptions.h>
#include <ParseTree.h>
#include <Visiter.h>
#include <VisiterImp.h>

/**
 * EXCEPTION DEFINITION
 **************************/
/**
 * Exception class.
 */
class ParserException {
	char* msg;

public:	
		ParserException(char* msg);
		virtual char* getMessage();
};

class ParserSemanticException : public ParserException {
	Token* tok;
	
	public:
		ParserSemanticException(Token* tok);		
		virtual char* getMessage();
};

class ParserUnexpectedEndException : public ParserException {
		
	public:
		ParserUnexpectedEndException(char* msg);

};

/**
* Parst den Quelltext. Dazu wird anhand der Grammatik die semantische Analyse durchgeführt und der
* Parse Tree dementsprechend aufgebaut.
*/
class Parser {
	Token* currentToken;
	SymtableInterface* symtable;
	ScannerFSMInterface* fsm;
	/// Baumobjekt
	Tree* tree;		//Baumobjekt
	/// Knotenobjekt
	Node* node;		//Knotenobjekt
	/// variabler Zeiger
	Tree* fixNodeL;	//variabler Zeiger
	/// variabler Zeiger für naechsten Baum
	Tree* fixNodeR;	//variabler Zeiger für naechsten Baum
	/// Blattobjekt
	Blatt* blatt;	//Blattobjekt

	Evaluator* evaluator;	// Interpreter

	bool eof;
	
public:
	/**
	* Constructor.
	*
	*/
	Parser();
	
	~Parser();
	
	/**
	* Start parsing.
	*
	*/
	void parse();

	/**
	* Sets input file
	*
	*/
	void setFile(char* filename);
	
private:
	
	/**
	* Reads the next token.
	* from the buffer and save it in this->currentToken.
	*
	*/
	void getNextToken();
	
	/**
	* Checks if the current token equals a given tokenType.
	* Throws NO exception if it doen't match.
	* @param tokenType The tokenType to compare with
	*/
	bool checkToken(int tokenType);
	
	/**
	* Checks if the current token equals a given tokenType.
	* Throws a exception it doen't match.
	* @param tokenType The tokenType to compare with
	*/
	bool checkTokenWithError(int tokenType);
	
	
	

	void StatementList();
			
	void StatementList2();
	
	void Statement();
	
	void EXP();
	
	void EXP2();
	
	void EXP3();
	
	void OP_EXP();
	
	void EXPLIST();
	
	void EXPLIST2();
	
	void OP();
	
	
	/*
	Hilfsfunktionen
	*/
	
	bool isOperator();
	
	bool isEXP3();
			
	
};
#endif
